using System;
using System.Configuration;

namespace Budgeteer.Services.Common
{
    public static class Config
    {
        static readonly ConfigService config = new ConfigService();

        public static string ConnectionString { get { return config.GetConnectionString(); } }
        public static string TestDataFolder { get { return config.GetString("TestDataFolder"); } }
    }

    public class ConfigService
    {
        public string GetString(string key)
        {
            string value = ConfigurationManager.AppSettings[key];
            if (value == null)
                throw new ConfigurationErrorsException("AppSettings configuration value " + key + "not found");
            return value;
        }

        public string GetConnectionString()
        {
            return GetString("ConnectionString");
        }

        public bool GetBoolean(string key)
        {
            return Convert.ToBoolean(GetString(key));
        }

        public DateTime GetDateTime(string key)
        {
            return Convert.ToDateTime(GetString(key));
        }

        public string this[string key]
        {
            get { return GetString(key); }
        }
    }
}